#include "MovableObject.h"
#include <vector>
#include "Collidable.h"
#include "Vector3.h"

MovableObject::MovableObject(): xVel(0), yVel(0)
{
}

Collidable* MovableObject::checkCollision(const std::vector<Collidable*>& plats)
{
	float scaledW = sx * cw;
	float scaledH = sy * ch;
	float leftA = position.x - scaledW;
	float topA = position.y + scaledH;
	float rightA = position.x + scaledW;
	float bottomA = position.y - scaledH;

	for (std::vector<Collidable*>::const_iterator it = plats.begin(); it != plats.end(); it++)
	{
		
		if ( (*it) == this || (*it)->dying )
			continue;
		float sxB = (*it)->sx;
		float syB = (*it)->sy;
		float leftB = (*it)->position.x - ( ((*it)->cw) * sxB );
		float topB = (*it)->position.y + ( ((*it)->ch) * syB );
		float rightB = (*it)->position.x + ( ((*it)->cw) * sxB );
		float bottomB = (*it)->position.y - ( ((*it)->ch) * syB );
	
		if ( (leftA < rightB) && (rightA > leftB) && (topA > bottomB) && (bottomA < topB) )
		{
			return (*it);
		}
	}
	return 0;
}

void MovableObject::onAnimationFinish(int state){}